package com.sumainfor.pc.epc.controller;

import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.epc.feign.GetUserInfoFeign;
import com.sumainfor.pc.epc.service.DecorateService;
import com.sumainfor.pc.epc.service.impl.FeignDecorateServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Decorate")
public class DecorateController {

    @Autowired
    private DecorateService decorateService;

    @Autowired
    private GetUserInfoFeign getUserInfoFeign;

    @Autowired
    FeignDecorateServiceImpl FeignDecorateServiceImpl;

    Logger log = LoggerFactory.getLogger(DecorateController.class);// 日志



    @ResponseBody
    @RequestMapping("getdeptByType")
    public JsonResult getdeptByType() throws Exception {

        Map<String,Object> params = new HashMap<String, Object>();
        String  usr = ContextUtils.getUserId();
        System.out.println(usr);
        params.put("userid", usr);//获取userid
        return getUserInfoFeign.getdeptByType(params);
    }


    @ResponseBody
    @RequestMapping("getSummain")
    public JsonResult getSummain(@RequestParam Map<String, Object> params) throws Exception {
        log.info("params---------->"+params);
        return decorateService.getSummain(params);
    }


    /**
     * 按照状态分页查询装修计划
     * @param params
     * @param pager
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("getDecoratePlanpage")
    public JsonResult getDecoratePlanpage(@RequestParam Map<String, Object> params,Pager pager) throws Exception {
        log.info("params---------->"+params);
        return decorateService.getDecoratePlanpage(params,pager);
    }

    /**
     * 创建装修计划
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("saveDecorate")
    public JsonResult saveDecorate(@RequestBody Map<String, Object> params) throws Exception {
        log.info("params---------->"+params);
        return decorateService.saveDecorate(params);
    }

    /**
     * 装修计划驳回之后修改重新发起
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("updatedecoratePlan")
    public JsonResult updatedecoratePlan(@RequestBody Map<String, Object> params) throws Exception {
        log.info("params---------->"+params);
        return decorateService.updatedecoratePlan(params);
    }


    /**
     * 驳回再次添加房源
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("updatedecoratePlanInfo")
    public JsonResult updatedecoratePlanInfo(@RequestBody Map<String, Object> params) throws Exception {
        log.info("params---------->"+params);
        return decorateService.updatedecoratePlanInfo(params);
    }

    /**
     * 获取uuid
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("getuuid")
    public JsonResult getuuid() {

        return decorateService.getuuid();
    }

    /**
     * 按照类型查询供应商
     *
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("getSupplier")
    public JsonResult getSupplier(@RequestParam Map<String, Object> params) {

        return decorateService.getSupplier(params);
    }


    /**
     * 分页查询装修计划
     *
     * @param params
     * @param pager
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("selectShopNames")
    public JsonResult selectShopNames(@RequestParam Map<String, Object> params) throws Exception {


        return decorateService.selectShopNames(params);
    }

    @ResponseBody
    @RequestMapping("selectComSpeName")
    public JsonResult selectComSpeName(@RequestParam Map<String, Object> params) throws Exception {


        return decorateService.selectComSpeName(params);
    }

    /**
     * 根据规格编号查询id
     *
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("getMonadByComSpeId")
    public JsonResult getMonadByComSpeId(@RequestParam Map<String, Object> params) {

        System.out.println(decorateService.getMonadByComSpeId(params));
        return decorateService.getMonadByComSpeId(params);
    }


    /**
     * 分页查询装修计划
     *
     * @param params
     * @param pager
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("getDecoratePlan")
    public JsonResult getDecoratePlan(@RequestParam Map<String, Object> params, Pager pager) throws Exception {


        return decorateService.getDecoratePlan(params, pager);
    }

    /**
     * 分页查询与参与的房源
     *
     * @param params
     * @param pager
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("getDecorate")
    public JsonResult getDecorate(@RequestParam Map<String, Object> params, Pager pager) throws Exception {


        return decorateService.getDecorate(params, pager);
    }


    /**
     * 查询装修阶段8大配置
     * @return
     */
    @ResponseBody
    @RequestMapping("getDep")
    public JsonResult getDep() throws Exception {
        return decorateService.getDep();
    }
    /**
     * 查询土建阶段三大配置
     * @return
     */
    @ResponseBody
    @RequestMapping("getBuilding")
    public JsonResult getBuilding() throws Exception {
        return decorateService.getBuilding();
    }

    /**
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("getSumHouByPlanId")
    public JsonResult getSumHouByPlanId(@RequestParam Map<String, Object> params) throws Exception {
        return decorateService.getSumHouByPlanId(params);
    }

    /**
     *工程经理审核装修计划批次
     * @return
     */
    @ResponseBody
    @RequestMapping("/updatetcepc_decorate_plan")
    public JsonResult updatetcepc_decorate_plan(@RequestParam Map<String, Object> params) throws Exception {
        JsonResult result=new JsonResult();
        if(decorateService.updatetcepc_decorate_plan(params)){
          return result.putSuccess("审核成功！");
        }else{
            return result.putFailed("服务器繁忙，请稍后重试！");
        }
    }

    /**
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("getBuildings")
    public JsonResult getBuildings(@RequestParam Map<String, Object> params) {
        return decorateService.getBuildings(params);
    }

    /**
     * 功能描述:
     * 装修中房源列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/29 14:55
     */
    @ResponseBody
    @RequestMapping(value = "/getDecorateHousingList",method= RequestMethod.POST)
    public JsonResult getDecorateHousingList(@RequestBody Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        int count=FeignDecorateServiceImpl.getDecorateHousingListCount(params);
        if(count==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,0);
        }
        List<Map<String,Object>> getDecorateHousingList=FeignDecorateServiceImpl.getDecorateHousingList(params);
        result=pageUtils.getJsonResult(getDecorateHousingList, params, count);
        return result;
    }


}
